<?php
	$title = 'title_'.$this->lang;
	$description = 'description_'.$this->lang;
?>
<div>
	<div class="box-h1">
		<h1 title="Search Books Result"><i>
			<?=Kohana::lang('site.viewcart')?> -> 
			<?=Kohana::lang('site.login')?> -> 
			<em><?=Kohana::lang('site.shipping')?></em> -> 
			<?=Kohana::lang('site.invoice')?> -> 
			<?=Kohana::lang('site.payment')?></i>
			<?=Kohana::lang('title.yourcart')?>
		</h1>
		<div class="box1 sform">
		<?php if(isset($carts['items']) and count($carts['items'])>0) { ?>
			<table id="cart-item-list" width="100%"><tr>
				<th width="50%"><?=Kohana::lang('site.product_name')?></th>
				<th width="10%">ISBN</th>
				<th width="10%" class="right"><?=Kohana::lang('site.price')?></th>
				<th width="10%" class="right"><?=Kohana::lang('site.quantity')?></th>
				<th width="10%" class="right"><?=Kohana::lang('site.subtotal')?></th>
			</tr><?php foreach($products as $product) { ?><tr>
				<td><?=$product->$title?></td>
				<td><?=$product->sku?></td>
				<td class="right">$<?=$product->price*1?></td>
				<td class="right"><?=$carts['items'][$product->id]['quantities']?></td>
				<td class="right">$<?=$product->price*$carts['items'][$product->id]['quantities']?></td>
			</tr><?php } ?><tr>
				<td style="background-color:#DADADA" colspan="5" class="right"><?=Kohana::lang('site.total')?>: $<?=$carts['subtotal']?></td>
			</tr></table>
			<br/>
			<form action="<?=url::site('cart/checkout/orderconfirm')?>" onsubmit="return Validator.Validate(this,3)" method="post" id="register">
				<h3><?=Kohana::lang('site.consignee_information')?></h3>
				<ul><li>
					<span class="label"><?=Kohana::lang('site.first_name')?></span>
					<span class="required">*</span>
					<span><input name="firstname" type="text" value="<?=$userinfo->firstname?>" dataType="ASCII" msg="用户名只能包含英文字母和数字"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.last_name')?></span>
					<span class="required">*</span>
					<span><input name="lastname" type="text" value="<?=$userinfo->lastname?>" dataType="ASCII" msg="用户名只能包含英文字母和数字"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.email')?></span>
					<span class="required">*</span>
					<span><input name="email" type="text" value="<?=$userinfo->email?>" dataType="Require" msg="请输入邮箱地址"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.phone')?></span>
					<span class="required">*</span>
					<span><input name="telephone" type="text" value="<?=$userinfo->phone?>" dataType="Require" msg="请输入联系电话"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.fax')?></span>
					<span class="required"></span>
					<span><input name="fax" type="text" value="<?=$userinfo->fax?>"/></span>
				</li></ul>
				<br/><h3><i>Note: Shipping address will be vaidated by UPS Address Validation tool (US customers only)</i><?=Kohana::lang('site.consignee_address')?></h3>
				<ul><li>
					<span class="label"><?=Kohana::lang('site.address_line')?> 1</span>
					<span class="required">*</span>
					<span><input type="text" id="shipping_address_1" name="shipping_address_1" dataType="Require" msg="请输入地址" value=""/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.address_line')?> 2</span>
					<span class="required"></span>
					<span><input type="text" id="shipping_address_2" name="shipping_address_2" value=""/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.city')?></span>
					<span class="required">*</span>
					<span><input id="shipping_city" name="shipping_city" type="text" value="" dataType="Require" msg="请输入城市名"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.state_province')?></span>
					<span class="required">*</span>
					<span id="shipping-zones"><select id="shipping_zone_id" name="shipping_zone_id">
						<?php foreach($zones as $item) { ?>
						<option value="<?=$item->id?>"><?=$item->name?></option>
						<?php } ?>
					</select></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.country')?></span>
					<span class="required">*</span>
					<span><select id="shipping_country_id" name="shipping_country_id" onchange="getZones(this.value, 'shipping')">
						<?php foreach($countries as $item) { ?>
						<option value="<?=$item->id?>" <?=($item->id == 223 ? 'selected="selected"' : '')?>><?=$item->name?></option>
						<?php } ?>
					</select></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.postal_code')?></span>
					<span class="required">*</span>
					<span><input id="shipping_zip_code" name="shipping_zip_code" type="text" value="<?=$userinfo->billing_zip_code?>" dataType="Require" msg="请输入邮政编码"/></span>
				</li></ul>
				<br/><h3><?=Kohana::lang('site.billing_address')?>&#160;&#160;&#160;&#160;&#160;<a onclick="copy_shipping_address()"><?=Kohana::lang('site.copy_above_address')?></a></h3>
				<ul><li>
					<span class="label"><?=Kohana::lang('site.address_line')?> 1</span>
					<span class="required">*</span>
					<span><input type="text" id="billing_address_1" name="billing_address_1" dataType="Require" msg="请输入地址" value=""/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.address_line')?> 2</span>
					<span class="required"></span>
					<span><input type="text" id="billing_address_2" name="billing_address_2" value=""/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.city')?></span>
					<span class="required">*</span>
					<span><input id="billing_city" name="billing_city" type="text" value="" dataType="Require" msg="请输入城市名"/></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.state_province')?></span>
					<span class="required">*</span>
					<span id="billing-zones"><select id="billing_zone_id" name="billing_zone_id">
						<?php foreach($zones as $item) { ?>
						<option value="<?=$item->id?>"><?=$item->name?></option>
						<?php } ?>
					</select></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.country')?></span>
					<span class="required">*</span>
					<span><select id="billing_country_id" name="billing_country_id" onchange="getZones(this.value, 'billing')">
						<?php foreach($countries as $item) { ?>
						<option value="<?=$item->id?>" <?=($item->id == 223 ? 'selected="selected"' : '')?>><?=$item->name?></option>
						<?php } ?>
					</select></span>
				</li><li>
					<span class="label"><?=Kohana::lang('site.postal_code')?></span>
					<span class="required">*</span>
					<span><input id="billing_zip_code" name="billing_zip_code" type="text" value="" dataType="Require" msg="请输入邮政编码"/></span>
				</li></ul>
				<br/><h3><?=Kohana::lang('site.express_information')?></h3>
				<input type="hidden" name="selResidential" id="selResidential" value="01"/>
				<input type="hidden" name="selPackaging" id="selPackaging" value="00"/>
				<input type="hidden" name="selRate" id="selRate" value="Regular+Daily+Pickup"/>
				<ul><!-- li>
					<span class="label">Address Type</span>
					<span class="required">*</span>
					<span><select name="selResidential" id="selResidential">
					   <option value="01">Residential</option>
					   <option value="02">Commercial</option>
					</select></span>
				</li><li>
					<span class="label">Packaging</span>
					<span class="required">*</span>
					<span><select name="selPackaging" id="selPackaging">
						<option value="00">Customer Packaging</option>
						<option value="01">UPS Letter Envelope</option>
						<option value="03">UPS Tube</option>
						<option value="21">UPS Express Box</option>
						<option value="24">UPS Worldwide 25KG Box</option>
						<option value="25">UPS Worldwide 10KG Box</option>
					</select></span>
				</li --><li>
					<span class="label"><?=Kohana::lang('site.service_type')?></span>
					<span class="required">*</span>
					<span><select name="selService" id="selService">
						<option value="1DA">Next Day Air</option>
						<option value="2DA">2nd Day Air</option>
						<option value="GND">Ground</option>
						<!-- option value="3DS">3 Day Select</option>
						<option value="1DP">Next Day Air Saver</option>
						<option value="2DM">2nd Day Air AM</option>
						<option value="1DM">Next Day Air Early AM</option>
						<option value="STD">Canada Standard</option>
						<option value="XPR">Worldwide Express</option>
						<option value="XDM">Worldwide Express Plus</option>
						<option value="XPD">Worldwide Expedited</option>
						<option value="WXS">Worldwide Saver</option -->
					</select></span>
				</li><!-- li>
					<span class="label">Rate</span>
					<span class="required">*</span>
					<span><select name="selRate" id="selRate">
						<option value="Regular+Daily+Pickup">Daily Pickup service</option>
						<option value="OP_WEB">Oncall Air Pickup Web (arrange on the web for UPS to pick up my packages)</option>
						<option value="OP_PHONE">Oncall Air Pickup Phone (arrange by phone for UPS to pick up my packages)</option>
						<option value="One+Time+Pickup">One Time Pickup</option>
						<option value="Letter+Center">Drop-box Letter Center</option>
						<option value="Customer+Counter">Customer Counter</option>
					</select></span>
				</li --><li>
					<span class="label"><?=Kohana::lang('site.shipping_expenses')?></span>
					<span class="required"></span>
					<span><input type="text" id="shipping_fare" name="shipping_fare" value="" readonly="readonly"/></span>
				</li><li>
					<span class="label"></span>
					<span class="required"></span>
					<span></span>
				</li><li>
					<span class="label"></span>
					<span class="required"></span>
					<span>
						<input type="Submit" id="genorder" name="genorder" value="<?=Kohana::lang('site.submit_order')?>" disabled="disabled"/>&#160;&#160;&#160;&#160;
						<button onclick="getShippinFare();return false;"><?=Kohana::lang('site.shipping_fare')?></button>&#160;&#160;&#160;&#160;
						<button onclick="window.location = '/cart.html';return false;"><?=Kohana::lang('site.viewcart')?></button>
					</span>
				</li></ul>
			</form>
			<div style="clear:both;"></div>
		<?php } else { ?>
			Your shopping cart is empty!
		<?php } ?>
		</div>
	</div>
</div>
<script type="text/javascript">
	function getShippinFare()
	{
		shipping_zip_code = $('shipping_zip_code').value;
		shipping_city = $('shipping_city').value;
		
		if (shipping_zip_code.trim() != '' && shipping_city.trim() != '') {
			params = shipping_zip_code + '/';
			params += shipping_city + '/';
			params += $('shipping_country_id').value + '/';
			params += $('selService').value + '/';
			params += escape($('selRate').value) + '/';
			params += $('selPackaging').value + '/';
			params += $('selResidential').value;
			
			//alert(params);
			ajax("<?=url::base()?>ajax/getshippingfare/" + params, 'script');
		}
		else
		{
			alert('Shipping Zip Code and Shipping City is empty!');
		}
		
		return false;
	}
	function getZones(country_id, domID)
	{
		ajax("<?=url::base()?>ajax/getzones/"+country_id+"/"+domID, 'update', domID+"-zones");
	}
	function copy_shipping_address()
	{
		$('billing_address_1').value = $('shipping_address_1').value;
		$('billing_address_2').value = $('shipping_address_2').value;
		$('billing_city').value = $('shipping_city').value;
		$('billing_zip_code').value = $('shipping_zip_code').value;
		
		objSelect = $('billing_country_id');
		objSelect[$('shipping_country_id').selectedIndex].selected = true;
		
		$('billing-zones').innerHTML = $('shipping-zones').innerHTML.replace(/shipping_zone_id/g, "billing_zone_id");
	}
</script>